home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / delftips / ti2842.asc < prev    next >
Encoding:
Text File  |  1996-09-15  |  5.9 KB  |  183 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2842
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  August 17, 1995                          PAGE  :  1/3
  11.  
  12.     TITLE  :  InterBase BLOB Fields: A Primer
  13.  
  14.  
  15.  
  16.  
  17. InterBase BLOB fields are not all the same. They actually consist in a
  18. variety of forms, or sub-types of the general BLOB type. Knowing which
  19. sub-type of BLOB field to use when is essential to creating database appl-
  20. ications that incorporate InterBase BLOB fields. BLOB fields come in three
  21. varieties: sub-type 0 and sub-type 1 (the two predefined sub-types), and
  22. user-defined sub-types.
  23.  
  24. Sub-type 0 BLOB fields are the type created when a CREATE command is 
  25. issued and a sub-type is not specified. For clarity in SQL syntax, though,
  26. it is possible to explicitly indicate that the BLOB field is to be of sub-
  27. type 0. This sub-type of BLOB field is for the storage of binary data.
  28. InterBase makes no analysis of the data stored, it just stores it in the
  29. BLOB field on a byte-for-byte basis. The most common intended use for BLOB
  30. fields in Windows applications is the storage of bitmap binary data, typi-
  31. cally for display in a TDBImage component. Either the BLOB field sub-type
  32. 0 or a user-defined sub-type BLOB field will work for this purpose.
  33.  
  34. The second predefined sub-type is 1. This BLOB field sub-type is designed
  35. for the storage of text. Typically, this is the free-form memo or notes
  36. data displayed and edited with the TDBMemo component. This BLOB field sub-
  37. type is better for storing text data than the VARCHAR field because,
  38. unlike with the VARCHAR field, there is no design-time limit placed on the
  39. storage capacity of the field.
  40.  
  41. In SQL syntax, the sub-type 1 BLOB field is created by following the BLOB
  42. field type keyword with the SUB_TYPE keyword and the integer one:
  43.  
  44.   CREATE TABLE WITHBLOB
  45.   (
  46.     ID CHAR(3) NOT NULL PRIMARY KEY,
  47.     MEMO BLOB SUB_TYPE 1,
  48.     AMOUNT NUMERIC
  49.   )
  50.  
  51. Aside from the two predefined BLOB field sub-types, there are user-defined
  52. sub-types. User-defined sub-types are designated by a negative integer
  53. value in association with the SUB_TYPE keyword. The actual integer value,
  54. as long as it is negative, is actually arbitrary and up to the discretion
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.   PRODUCT  :  Delphi                                 NUMBER  :  2842
  69.   VERSION  :  All
  70.        OS  :  Windows
  71.      DATE  :  August 17, 1995                          PAGE  :  2/3
  72.  
  73.     TITLE  :  InterBase BLOB Fields: A Primer
  74.  
  75.  
  76.  
  77.  
  78. of the table creator. A designation of -1 is functionally the same as that
  79. of a -2. The only consideration when using user-defined sub-types is
  80. ensuring that the same type of binary data is stored for every row in the
  81. table for a BLOB field of a given user-defined sub-type. InterBase will
  82. not evaluate whether this criteria is met, and it is the responsibility of
  83. the application inserting the binary data to store the appropriate type of
  84. data. No error will occur from the InterBase side if an incorrect type of
  85. binary data is stored in a user-defined BLOB field sub-type, but an appl-
  86. ication can incur difficulties if it is expecting one type of data but
  87. encounters another.
  88.  
  89. A BLOB field of a user-defined sub-type is created with the SQL syntax
  90. such as that below:
  91.  
  92.   CREATE TABLE IMAGE_DATA
  93.   (
  94.     FILENAME CHAR(12) NOT NULL PRIMARY KEY,
  95.     BITMAP BLOB SUB_TYPE -1,
  96.     EXEs BLOB SUB_TYPE -2,
  97.   )
  98.  
  99. When using a table created with the above command, the field BITMAP would
  100. only be used to store one distinct type of binary data for all records. In
  101. this case, bitmap data. The field EXEs implies the storage of executable
  102. files loaded from disk. If an application using this table were to mis-
  103. takenly store binary data that should have been in the EXEs field into the
  104. BITMAP field, InterBase would generate no errors, but the application
  105. would have extreme difficulties displaying a stored executable file in a
  106. TDBImage component.
  107.  
  108. InterBase BLOB fields and Delphi
  109. --------------------------------
  110.  
  111. When defining TField objects for InterBase BLOB fields in Delphi, the
  112. various BLOB field sub-types are assigned TField derivative types as
  113. follows:
  114.  
  115.   Sub-type 0:   TBlobField
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.   PRODUCT  :  Delphi                                 NUMBER  :  2842
  130.   VERSION  :  All
  131.        OS  :  Windows
  132.      DATE  :  August 17, 1995                          PAGE  :  3/3
  133.  
  134.     TITLE  :  InterBase BLOB Fields: A Primer
  135.  
  136.  
  137.  
  138.  
  139.   Sub-type 1:   TMemoField
  140.   User-defined: TBlobField
  141.   
  142. Because both the predefined sub-type 0 and user-defined sub-types are
  143. recognized as TBlobField objects, care must be taken when designing an
  144. application to not mistake a field of one sub-type for that of another.
  145. The only way to differentiate between a field of sub-type 0 from that of
  146. a user-defined type is by viewing the metadata information for the table,
  147. which cannot be done from within Delphi. The Local InterBase Server
  148. utility WISQL can be used to view table metadata.
  149.  
  150. InterBase BLOB fields and Database Desktop
  151. ------------------------------------------
  152.  
  153. The Database Desktop utility that comes with Delphi (DBD) does not create
  154. user-defined subtypes. When using BLOB fields created in Database Desktop,
  155. use the "BLOB" field type for binary data, including bitmap data. This
  156. creates a BLOB field of the predefined sub-type 0.
  157.  
  158. The DBD also offers a BLOB field type TEXT BLOB. This is equivalent to the
  159. pre-defined subtype 1, and should be used where free-form text storage
  160. will be needed. While it is functionally equivalent to the pre-defined
  161. subtype 1 BLOB field, it will appear with a slightly different type des-
  162. ignation if you view the metadata for the table in the WISQL utility.
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. DISCLAIMER: You have the right to use this technical information
  180. subject to the terms of the No-Nonsense License Statement that
  181. you received with the Borland product to which this information
  182. pertains.
  183.